package edu.pku.sei.transformation.editor.views.tree;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.swt.graphics.Image;

import edu.pku.sei.modeler.explorer.registry.ITreeViewLabelProvider;
import edu.pku.sei.modeler.model.core.MetaNamedElement;
import edu.pku.sei.modeler.model.core.MetaPackage;
import edu.pku.sei.modeler.model.structure.MetaDiagram;
import edu.pku.sei.transformation.editor.internal.TransformationEditorProject;
import edu.pku.sei.transformation.editor.model.GraphicalDomain;
import edu.pku.sei.transformation.editor.model.Key;
import edu.pku.sei.transformation.editor.model.ModelType;
import edu.pku.sei.transformation.editor.model.Rule;
import edu.pku.sei.transformation.editor.model.Transformation;
import edu.pku.sei.transformation.editor.model.execution.Model;
import edu.pku.sei.transformation.editor.model.execution.RuleExecution;
import edu.pku.sei.transformation.editor.model.execution.TransformationExecution;
import edu.pku.sei.transformation.editor.model.goal.TransformationGoal;
import edu.pku.sei.transformation.editor.model.test.CheckPoint;
import edu.pku.sei.transformation.editor.model.test.TestCase;
import edu.pku.sei.transformation.editor.model.variable.ConnectionVariable;
import edu.pku.sei.transformation.editor.model.variable.ObjectVariable;
import edu.pku.sei.transformation.editor.model.variable.Variable;
import edu.pku.sei.transformation.editor.views.icons.IconsProvider;

public class EditorTreeViewLabelProvider implements ITreeViewLabelProvider {

	@Override
	public Image getImage(Object element) {
		ImageDescriptor iDesc = IconsProvider
				.getImageDescriptor(IconsProvider.FILE_ICO);
		if (element instanceof Transformation) {
			iDesc = IconsProvider
					.getImageDescriptor(IconsProvider.TRANSFORMATION_ICO);
		} else if (element instanceof Rule) {
			iDesc = IconsProvider.getImageDescriptor(IconsProvider.RULE_ICO);
		} else if (element instanceof MetaPackage) {
			iDesc = IconsProvider.getImageDescriptor(IconsProvider.TREE_ICO);
		} else if (element instanceof GraphicalDomain) {
			iDesc = IconsProvider
					.getImageDescriptor(IconsProvider.AREA_DIAGRAM_ICO);
		} else if (element instanceof ObjectVariable) {
			iDesc = IconsProvider.getImageDescriptor(IconsProvider.NODE_ICO);
		} else if (element instanceof Key) {
			iDesc = IconsProvider.getImageDescriptor(IconsProvider.KEY_ICO);
		} else if (element instanceof ConnectionVariable) {
			iDesc = IconsProvider.getImageDescriptor(IconsProvider.CONNECTION_ICO);
		} else if (element instanceof ModelType) {
			iDesc = IconsProvider.getImageDescriptor(IconsProvider.MODEL_ICO);
		} else if (element instanceof TransformationGoal) {
			iDesc= IconsProvider.getImageDescriptor(IconsProvider.GOAL_ICO);
		} else if (element instanceof MetaDiagram) {
			iDesc = IconsProvider.getImageDescriptor(IconsProvider.AREA_DIAGRAM_ICO);
		} else if (element instanceof TestCase) {
			iDesc = IconsProvider.getImageDescriptor(IconsProvider.TEST2_ICO);
		} else if (element instanceof TransformationExecution) {
			iDesc = IconsProvider.getImageDescriptor(IconsProvider.EXECUTION_ICO);
		} else if (element instanceof RuleExecution) {
			iDesc = IconsProvider.getImageDescriptor(IconsProvider.EXECUTION2_ICO);
		} else if (element instanceof Model) {
			iDesc = IconsProvider.getImageDescriptor(IconsProvider.MODEL_ICO);
		} else if (element instanceof CheckPoint) {
			iDesc = IconsProvider.getImageDescriptor(IconsProvider.CHECKPOINT_ICO);
		}
			
		return iDesc.createImage();
	}

	@Override
	public String getText(Object element) {
		if (element instanceof MetaNamedElement) {
			return ((MetaNamedElement) element).getName();
		} else if (element instanceof Transformation) {
			return element.toString();
		} else if (element instanceof Rule) {
			return ((Rule)element).getName();
		} else if (element instanceof GraphicalDomain) {
			return element.toString();
		} else if (element instanceof Variable) {
			return element.toString();
		} else if (element instanceof Key) {
			return element.toString();
		}

		else {
			return element.toString();
		}
	}

	@Override
	public void addListener(ILabelProviderListener listener) {
		// TODO Auto-generated method stub

	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean isLabelProperty(Object element, String property) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void removeListener(ILabelProviderListener listener) {
		// TODO Auto-generated method stub

	}

	@Override
	public String getNature() {
		return TransformationEditorProject.PROJECT_NATURE;
	}

}
